package ${packageName}.service.impl;
// Generated ${date} by Hibernate Tools ${version}

<#assign classbody>
<#assign declarationName = pojo.importType(pojo.getDeclarationName())>
<#assign daoName = pojo.importType("${pojo.packageName}.I${declarationName}Dao")>
import ${pojo.getQualifiedDeclarationName()};
import ${packageName}.dao.I${declarationName}Dao;
import ${packageName}.service.${declarationName}Service;
/**
 * Service implementation class for model ${declarationName}.
 * @see ${pojo.getQualifiedDeclarationName()}
 * @author Extras Tools
 */
@${pojo.importType("org.springframework.stereotype.Service")}
public class ${declarationName}ServiceImpl extends ${pojo.importType("com.xcesys.extras.core.service.impl.BaseCrudServiceImpl")}<${declarationName}> implements 
 	${pojo.importType("${pojo.packageName}.${declarationName}Service")} {
	@${pojo.importType("org.springframework.beans.factory.annotation.Autowired")}
	private ${daoName} dao;
	
	@${pojo.importType("java.lang.Override")}
	public ${daoName} getDao() {
		return dao;
	}
	
	@${pojo.importType("java.lang.Override")}
	public ${pojo.importType("com.xcesys.extras.core.model.PageResult")}<${declarationName}> findByCriteria(
		${pojo.importType("com.xcesys.extras.core.model.QueryCriteria")}<String, Object> criteria) {
		//TODO: please modify follows lines to finish findByCriteria method.		
		String fromClause = " select c from ${declarationName} c";
		String[] whereBodies = new String[] {"1=1"
			<#foreach property in pojo.getAllPropertiesIterator()>
	        ,"c.${property.name} = :${property.name}" <#foreach column in property.columnIterator><#if column.comment?exists && column.comment?trim?length!=0> // ${column.comment} </#if></#foreach>
			</#foreach>
		};
		String joinClause = "";
		
		//TODO: please change default sort field.		
		// default sort
		String orderClause = ${pojo.importType("com.xcesys.extras.core.util.StringUtil")}.isNullOrBlank(criteria.getSort()) ? "c.id"
				: null;
				
		// execute query
		${pojo.importType("com.xcesys.extras.core.model.PageResult")}<${declarationName}> result = getDao().queryQueryCriteria(fromClause,
				joinClause, orderClause, whereBodies, criteria);
		return result;
	}
}
</#assign>
${pojo.generateImports()}
${classbody}